package com.atguigu.controller;

import com.atguigu.entities.User;
import com.atguigu.service.UserService;
import io.swagger.models.auth.In;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * @author lbstart
 * @create 2021-06-27 9:38
 */
@RestController
@Slf4j
public class UserController {
    @Resource
    private UserService userService;

    @RequestMapping("/user/add")
    public String add()
    {
        for (int i = 1; i <=20; i++) {
            User user = new User();
            user.setSex((byte)new Random().nextInt(2));
            user.setUsername("zzyy"+i);
            int v = (int) ((Math.random() * 9 + 1) * 100000);
            user.setPassword(v+"");
            userService.add(user);
        }
        return "------add user success";
    }

    @RequestMapping("/user/del")
    public String del(Integer id){
        userService.del(id);
        return "---del user success";
    }

    @RequestMapping("/find")
    public List<User> find(Integer id) {
        User byId = userService.getById(id);
        List list = new ArrayList();
        list.add(byId);
        return list;
    }


}
